package com.project.controller;

import com.project.bean.BuyCarBean;
import com.project.bean.UserBean;
import com.project.service.IBuyCarService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("buyCar")
public class BuyCarController {
    @Autowired
    private IBuyCarService buyCarService;

    @RequestMapping("findById")
    @RequiresPermissions({"user:manage"})
    List<BuyCarBean> findById(HttpServletRequest request){
        UserBean userBean= (UserBean) request.getSession().getAttribute("loginUser");
        return buyCarService.findById(userBean.getUserId());
    }

    @RequestMapping("updateById")
    @RequiresPermissions({"user:manage"})
    public  String updateById(Integer buyCarId,Integer newPrice,Integer newNum){
        buyCarService.updateById(buyCarId,newPrice,newNum);
        return "success";
    }

    @RequestMapping("del")
    @RequiresPermissions({"user:manage"})
    public  String  del(Integer buyCarId){
        buyCarService.del(buyCarId);
        return "success";
    }
}
